
#include "Board.h"
#include <random>
#include <time.h>
#include <conio.h>
#include "AI2048.h"

int main()
{
	Board b;
	//b.Value(0, 0) = 4;
	//b.Value(0, 1) = 4;
	//b.Value(0, 2) = 2;
	//b.Value(0, 3) = 2;
	//b.Value(1, 0) = 2;
	//b.Value(2, 0) = 2;
	b.Value(3, 1) = 2;
	//b.Value(3, 2) = 2;
	//b.MoveRight();

	srand(time(0));
	//rand(
	while (1) {
		int emptyCount = b.AvailableCellsCount();
		if (!emptyCount)
			break;

		const Cell *cells = b.AvailableCells();
		int i = rand() % emptyCount;
		int v = rand() % 100;
		v = v < 95 ? 2 : 4;
		b.Value(cells[i]) = v;
		b.Print(cells[i]);

		AI2048 ai(b);
		int move = ai.GetBestMove(5);

		if (0 == move)
		{
			printf("Left\n");
			b.MoveLeft();
		}
		else if (1 == move)
		{
			printf("Right\n");
			b.MoveRight();
		}
		else if (2 == move)
		{
			printf("Up\n");
			b.MoveUp();
		}
		else
		{
			printf("Down\n");
			b.MoveDown();
		}

		_sleep(0);
	}

	printf("End");
	_getch();

	return 0;
}